import { message } from 'antd'

// 上传通用路径
// export const uploadUrl = 'http://8.141.48.47:8099/storage/upload';
export const uploadUrl = 'http://134.122.133.76:8099/storage/upload';

export function getBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
  });
}

export function beforeUploadImage(file) {
  const isJpgOrPng = file.type === "image/jpeg" || file.type === "image/png";
  if (!isJpgOrPng) {
    message.error("You can only upload JPG/PNG file!");
  }
  const isLt2M = file.size / 1024 / 1024 < 2;
  if (!isLt2M) {
    message.error("Image must smaller than 2MB!");
  }
  return isJpgOrPng && isLt2M;
}

export function beforeUploadVideo(file) {
  const isJpgOrPng = true;
  // const isJpgOrPng = file.type === "image/jpeg" || file.type === "image/png";
  // if (!isJpgOrPng) {
  //   message.error("You can only upload mp4/ file!");
  // }
  const isLt50M = file.size / 1024 / 1024 < 50;
  if (!isLt50M) {
    message.error("Image must smaller than 50MB!");
  }
  return isJpgOrPng && isLt50M;
}
